package com.css.zfzx.sjcj.common.division.service;

import com.css.bpm.platform.api.local.PlatformAPI;
import com.css.bpm.platform.org.dept.repository.entity.DeptEntity;
import com.css.zfzx.sjcj.common.division.repository.MyDivisionRepository;
import com.css.zfzx.sjcj.common.vo.DivisionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MyDivisionServiceImpl implements MyDivisionService {
    @Autowired
    MyDivisionRepository myDivisionRepository;

    @Override
    public DivisionVo getDivision(String usersId) {
        DeptEntity mainDept = PlatformAPI.getOrgAPI().getUserAPI().getMainDept(usersId);
        String divisionId = mainDept.getDivisionId();
        DivisionVo divisionVo = myDivisionRepository.findDivision(divisionId);
        String code = divisionVo.getDivisionCode();
        DivisionVo vo=new DivisionVo();
        if(code.contains("0000")){//省
            vo.setProvinceName(divisionVo.getAreaName());
        }else if("00".equals(code.substring(4))){//市
            vo.setProvinceName(divisionVo.getCityName());
            vo.setCityName(divisionVo.getAreaName());
        }else {
            vo.setCityName(divisionVo.getCityName());
            vo.setAreaName(divisionVo.getAreaName());
            //北京，上海，天津，重庆
            if("11".equals(code.substring(0, 2))||"31".equals(code.substring(0, 2))
                    ||"12".equals(code.substring(0, 2))||"50".equals(code.substring(0, 2))){
                vo.setProvinceName(divisionVo.getCityName());
            }else {
                vo.setProvinceName(divisionVo.getProvinceName());
            }
        }
        return vo;
    }

}
